package com.kws.merchant.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.kws.merchant.domain.AfterSalesHelp;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kws.merchant.mapper.AfterSalesHelpMapper;
import com.kws.merchant.service.AfterSalesHelpService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.List;

/**
 * 售后-帮助中心(AfterSalesHelp)表服务实现类
 *
 * @author yxy
 * @since 2024-10-22 19:23:09
 */
@Service("afterSalesHelpService")
public class AfterSalesHelpServiceImpl extends ServiceImpl<AfterSalesHelpMapper, AfterSalesHelp> implements AfterSalesHelpService {

    @Resource
    private AfterSalesHelpMapper afterSalesHelpMapper;


    /**
     * 分页查询列表
     *
     * @param afterSalesHelp
     * @return
     */
    @Override
    public Page<AfterSalesHelp> pageList(AfterSalesHelp afterSalesHelp) {
        Page<AfterSalesHelp> page = new Page<>(0, 10);
        LambdaQueryWrapper<AfterSalesHelp> queryWrapper = Wrappers.<AfterSalesHelp>lambdaQuery();
        return this.page(page, queryWrapper);
    }

    /**
     * 通过pid查询所有数据
     * @param pid
     * @return
     */
    @Override
    public List<AfterSalesHelp> listByPid(Long pid) {
        return this.list(Wrappers.<AfterSalesHelp>lambdaQuery().eq(AfterSalesHelp::getPid,pid));
    }

    /**
     * 查询所有问题和答案
     * @return
     */
    @Override
    public List<AfterSalesHelp> getHelp() {
        List<AfterSalesHelp> list = this.listByPid(0l);
        list.forEach(x->{
            List<AfterSalesHelp> answerList = this.listByPid(x.getId());
            x.setList(answerList);
        });
        return list;
    }

    /**
     * 模糊查询问题
     * @param question
     * @return
     */
    @Override
    public List<AfterSalesHelp> listByQuestion(String question) {
        return this.list(Wrappers.<AfterSalesHelp>lambdaQuery().like(AfterSalesHelp::getQuestion,question));
    }


}
